using System.Collections.Specialized;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.Collections
{
    [TestClass]
    public class WhenAddOrReplaceOnDuplicateKey
    {

        [TestMethod]
        public void ShouldReplaceExistingValues()
        {
            NameValueCollection collection = new NameValueCollection();
            collection.Add("key1", "val1");
            collection.Add("key2", "val2");

            NameValueCollection nameValuesToAdd = new NameValueCollection();
            nameValuesToAdd.Add("key2", "val2updated");
            nameValuesToAdd.Add("key3", "val3");

            NameValueCollection expected = new NameValueCollection();
            expected.Add("key1", "val1");
            expected.Add("key2", "val2updated");
            expected.Add("key3", "val3");

            NameValueCollectionHelper.AddOrReplaceOnDuplicateKey(collection, nameValuesToAdd);
            AssertNameValueCollection.HaveSameElements(expected, collection);
        }
    }
}